# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     day171_pyqt5_color
   Description :   This example draws three rectangles in three
                   different colours.
   Author :       fuml
   date：          2019/10/12
-------------------------------------------------
   Change Activity:
                   2019/10/12:
-------------------------------------------------
"""
import sys
from PyQt5.QtWidgets import QWidget,QApplication
from PyQt5.QtGui import QPainter,QColor,QBrush

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300,300,350,150)
        self.setWindowTitle('Colors')
        self.show()

    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        self.drawRectangles(qp)
        qp.end()

    def drawRectangles(self,qp):
        col = QColor(0,0,0)
        col.setNamedColor('#d4d4d4')
        qp.setPen(col)
        qp.setBrush(QColor(200,0,0))
        qp.drawRect(10,15,90,60)

        qp.setBrush(QColor(255,80,0,160))
        qp.drawRect(130,15,90,60)

        qp.setBrush(QColor(25,0,90,200))
        qp.drawRect(250,15,90,60)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())